//
//  LihongqianViewController.m
//  Music
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LihongqianViewController.h"
#import <AFNetworking.h>
#import "BigModel.h"
#import "SingrecommendTableViewCell.h"
#import "ThreeTableViewCell.h"
#import "RealTableViewCell.h"
#import "DxScrollView.h"
#import "MoreViewController.h"
#import "LHQLikeViewController.h"
#import "smallModel.h"
#import "LHQListerViewController.h"
#import "LHQRecommendDetailViewController.h"
#import "LHQHotViewController.h"
#import "RefreshViewController.h"
#import "ExclusiveDetailsectionSixViewController.h"
#import "ExclusiveMoreViewController.h"
#import "ExclusiveDetailViewController.h"
#import "LHQSearchViewController.h"
@interface LihongqianViewController ()<UITableViewDelegate,UITableViewDataSource,DxScrollViewDelegate,PassValue,passValue>
@property(nonatomic,retain)UIView *viewSlider;
@property(nonatomic,retain)NSMutableArray  *dataSoureArray;
@property(nonatomic,retain)UITableView  *tableView;
@property(nonatomic,retain)NSMutableArray  *twoDataSource;
@property(nonatomic,retain)NSMutableArray  *threeDataSource;
@property(nonatomic,retain)NSMutableArray  *lastDataSource;
@property(nonatomic,assign)NSInteger  number;
@property(nonatomic,retain)NSArray  *titleArray;
@property (nonatomic, retain)DxScrollView  *scrollView;  // 封装好的轮播图
@property (nonatomic,retain)NSMutableArray  *lunboDataSource;
@property (nonatomic,retain)UIImageView  *imageView;
@property (nonatomic,retain)UIBarButtonItem  *music;
@end

@implementation LihongqianViewController
-(void)viewWillAppear:(BOOL)animated
{
   self.navigationController.tabBarController.tabBar.hidden = NO;
    
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.dataSoureArray = [NSMutableArray  array];
        self.twoDataSource = [NSMutableArray  array];
        self.threeDataSource = [NSMutableArray  array];
        self.lastDataSource = [NSMutableArray  array];
        self.titleArray = [NSArray  array];
        self.lunboDataSource = [NSMutableArray  array];
      
    
    }
    
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"视听";
    self.navigationController.navigationBar.translucent = NO;
    [self  getDataSource];
  
    self.titleArray = [NSArray  arrayWithObjects:@"歌曲推荐",@"新歌新碟",@"热门歌单",@"独家艺人",@"独家专区",@"亚洲新歌榜", nil];
     self.navigationController.navigationBar.barStyle = 1;
   [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem  alloc]initWithImage:[[UIImage  imageNamed:@"myMusic"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(didslider:)];
    
   
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage  imageNamed:@"MusicSearch"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(didsearch:)];

    
    
    
//    for (NSInteger i = 1; i<=26; i++) {
//       
//        NSArray  *array = [NSArray  arrayWithContentsOfFile:[NSString  stringWithFormat:@"%ld",i]];
//        self.imageView = [[UIImageView  alloc] initWithImage:[[UIImage  imageNamed:@"1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//        self.imageView.frame = CGRectMake(Screenwidth/2+40, 10, 40, 40);
//        [self.view  addSubview:_imageView];
//       // self.imageView.animationImages = array;
//      [self.imageView  startAnimating];
//    }
}
-(void)didslider:(UIBarButtonItem *)slider
{
    
}
-(void)didsearch:(UIBarButtonItem *)search
{
    LHQSearchViewController  *sea = [[LHQSearchViewController  alloc] init];
    [self.navigationController  pushViewController:sea animated:YES];
}
-(void)didmusic :(UIBarButtonItem *)music
{
    
    
}
//两个块
-(void)passStr:(NSString *)str string:(NSString *)string{
    if ([string integerValue]==2921) {
        LHQLikeViewController  *like = [[LHQLikeViewController  alloc] init];
        like.title = str;
        [self.navigationController  pushViewController:like animated:YES];
    }
   
    else{
        LHQListerViewController  *lister = [[LHQListerViewController  alloc] init];
        lister.title = str;
        [self.navigationController  pushViewController:lister animated:YES];
    
    }

}
//三个图传值跳跃
-(void)passNumber:(NSInteger)number
{
    NSString  *str = [NSString  stringWithFormat:@"%ld",number];
    if (str.length == 9) {
        LHQHotViewController  *hot = [[LHQHotViewController  alloc] init];
        hot.hotNumber = number;
        [self.navigationController  pushViewController:hot animated:YES];
    }
    else if (str.length == 7){
        RefreshViewController  *refresh = [[RefreshViewController  alloc] init];
        refresh.refreshCount = number;
        [self.navigationController  pushViewController:refresh
                                              animated:YES];
    }
    else{
    LHQRecommendDetailViewController  *recommend = [[LHQRecommendDetailViewController   alloc] init];
    
    recommend.count = number;
    [self.navigationController  pushViewController:recommend animated:YES];
    }
}
-(void)getDataSource
{
    NSString  *url = sightUrl;
    [MyTools   getNetWithUrl:url body:nil header:nil response:LHQJSON success:^(id result) {
        NSDictionary  *dic = (NSDictionary *)result;
        NSMutableArray  *temp = dic[@"data"];
        for (NSDictionary  *dict in temp) {
            BigModel  *model = [[BigModel  alloc]initWithDic:dict];
            [self.dataSoureArray  addObject:model];
           }
       [self.tableView reloadData];
        [self  tableViewSubView];
        [self  LUNBO];
    } failure:^(NSError *error) {
    }];
}
-(void)LUNBO
{
    NSString  *URL = sightUrl;
    [MyTools  getNetWithUrl:URL body:nil header:nil response:LHQJSON success:^(id result) {
        
        NSMutableArray *array = [result objectForKey:@"data"];
        NSDictionary *dic = [array objectAtIndex:0];
        NSMutableArray *first = [dic objectForKey:@"data"];
        NSMutableArray *second = [NSMutableArray array];
        for (NSDictionary *aDic in first) {
            [second addObject:aDic];
            BigModel  *model = [[BigModel  alloc]initWithDic:aDic];
        [self.lunboDataSource addObject:model];
       }
        [self.scrollView setImages:second state:YES];
        [second removeAllObjects];
        [self.tableView  reloadData];
    } failure:^(NSError *error) {
        
    }];
}
-(void)tableViewSubView
{
    UIView *heardView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screenwidth, 0.5*Screenwidth)];
    self.scrollView = [[DxScrollView alloc]initWithFrame:CGRectMake(10, 5, Screenwidth-20, 0.5 * (Screenwidth-20)+5)];
    _scrollView.layer.cornerRadius = 10;
    _scrollView.layer.masksToBounds = YES;
    _scrollView.delegate = self;
    [heardView addSubview:self.scrollView];
    
    self.tableView = [[UITableView  alloc]initWithFrame:CGRectMake(0, 0, Screenwidth, Screenheight-49-20) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableHeaderView = heardView;
    [self.tableView  registerClass:[SingrecommendTableViewCell   class] forCellReuseIdentifier:@"singcell"];
    [self.tableView  registerClass:[ThreeTableViewCell  class] forCellReuseIdentifier:@"threecell"];
    [self.tableView  registerClass:[RealTableViewCell  class] forCellReuseIdentifier:@"real"];
    [self.view  addSubview:_tableView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 6;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 4) {
        return 5;
    }
    return 1;

}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.number = indexPath.section;
     NSInteger  index =indexPath.section;
    if (index == 0) {
        SingrecommendTableViewCell  *cell = [tableView  dequeueReusableCellWithIdentifier:@"singcell"];
        BigModel  *model = [self.dataSoureArray  objectAtIndex:2];
        cell.selectedNum = indexPath.row;
        cell.dataSource = model.data.mutableCopy;
        cell.delegate = self;
       return cell;
    }
  else  if ( index == 1 || index == 2 || index == 3  ) {
       ThreeTableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"threecell"];
      BigModel  *model = [self.dataSoureArray objectAtIndex:index+2 ];
    cell.threedataSource = model.data.mutableCopy;
      cell.delegate = self;
    return cell;
  }
//    else  if ( index == 4) {
//          ThreeTableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"threecell"];
//          BigModel  *model = [self.dataSoureArray objectAtIndex:index+1 ];
//          cell.threedataSource = model.data.mutableCopy;
//          cell.delegate = self;
//          return cell;
//    }
  else if(index == 4 || index == 5 ){
        RealTableViewCell  *cell  = [tableView  dequeueReusableCellWithIdentifier:@"real"];
        BigModel  *model = [self.dataSoureArray  objectAtIndex:index+2];
       cell.model = [model.data  objectAtIndex:indexPath.row];
       return cell;
   }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{  if(indexPath.section ==0){
    return 90;
   }
   else if (indexPath.section == 2 ) {
        return 300;
    }
   else if (indexPath.section == 4 || indexPath.section == 5) {
       return 100;
   }
    return 155;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView  *view = [[UIView  alloc]initWithFrame:CGRectMake(0, -4, Screenwidth, 20)];
    UILabel  *label = [[UILabel  alloc]initWithFrame:CGRectMake(Screenwidth/2-30, view.frame.origin.y, 100, 20)];
    label.text =[self.titleArray  objectAtIndex:section];
    label.font =[UIFont  fontWithName:@"Helvetica-Oblique" size:14];
   [view  addSubview:label];
    if(section == 1 || section == 2 || section == 3||section == 4){
    UIButton  *button = [UIButton  buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(label.frame.origin.x+140, label.frame.origin.y, 80, 20);
    [button  setTitle:@"更多＞" forState:UIControlStateNormal];
    [button  setTitleColor:[UIColor  blackColor] forState:UIControlStateNormal];
    button.titleLabel.font =[UIFont  fontWithName:@"Helvetica-Oblique" size:14];
    button.tag = section;
    [button  addTarget:self action:@selector(detailButton:) forControlEvents:UIControlEventTouchUpInside];
    [view  addSubview:button];
    }
    return view;
}
//更多详情方法
-(void)detailButton:(UIButton *)button
{
    
    if (button.tag == 1) {
        MoreViewController  *More = [[MoreViewController  alloc] init];
        
        [self.navigationController  pushViewController:More animated:YES];
        
    }
    if (button.tag == 4) {
        ExclusiveMoreViewController  *Exclusive = [[ExclusiveMoreViewController  alloc] init];
        [self.navigationController  pushViewController:Exclusive animated:YES];
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 5){
        ExclusiveDetailsectionSixViewController  *detailView = [[ExclusiveDetailsectionSixViewController  alloc] init];
       [self.navigationController  pushViewController:detailView animated:YES];
    }
    if (indexPath.section == 4 ) {
            BigModel  *model = self.dataSoureArray[6];
            smallModel  *smallMode = model.data[indexPath.row];
            NSString  *url = smallMode.id;
        ExclusiveDetailViewController  *detail = [[ExclusiveDetailViewController  alloc] init];
            detail.number = indexPath.row;
            NSString  *str  = smallMode.action[@"value"];
            detail.numId = url;
            detail.url =  str ;
           
        [self.navigationController  pushViewController:detail animated:YES];
      
    
    }
    
  }






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
   }

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
